#pragma once

#include "../../Util/Control/CGridListCtrlEx/CGridListCtrlGroups.h"
#include "../../TXDataProcessor/DataProcessor/DBProcessor.h"

class CTXDataGrid : public CGridListCtrlGroups, public CCommMsgLink
{
public:
	CTXDataGrid(void);
	virtual ~CTXDataGrid(void);

	virtual BOOL			Bind(LPCTSTR lpszTableName, LPCTSTR lpszSQL = NULL);	
	virtual void _stdcall	OnResultData(IRequestManager* pRequestManager);

	virtual int				InsertColumnTrait(int nCol, LPCTSTR lpszDisplayName, LPCTSTR lpszColumnName, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1, CGridColumnTrait* pTrait = NULL);
	
	AFX_INLINE void			AutoColumn(BOOL bAuto = TRUE)		{ m_bAutoColumns = bAuto; }
	virtual void			AdjustColumn();

protected:
	DECLARE_MESSAGE_MAP();

private:
	DBProcessor::Query				m_rmQuery;
	CMap<int,int,CString,LPCTSTR>	m_mapColumnName;

	CString		m_strTableName;
	CString		m_strSQL;
	BOOL		m_bAutoColumns;

public:
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnLvnEndlabeleditList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnDestroy();
	BOOL UpdateTableVersion(LPCTSTR lpszTableName);
};
